package com.raymond.http.netty;

import lombok.Getter;

import java.net.*;
import java.util.Objects;

/**
 * @author :  raymond
 * @version :  V1.0
 * @date :  2021-12-11 16:17
 */
@Getter
public class HttpAddress {

    public static final String HTTPS = "https";

    private String host;

    private int port;

    private boolean ssl;

    public HttpAddress(String url) {
        this(URI.create(url));
    }

    public HttpAddress(URI uri) {
        this.ssl = uri.getScheme().toUpperCase().equals(HTTPS);
        this.host = uri.getHost();
        this.port = uri.getPort();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        HttpAddress that = (HttpAddress) o;
        return that.host.equals(this.host) && that.port == this.port;
    }

    @Override
    public int hashCode() {
        return Objects.hash(host, port);
    }
}
